import quicksort.*;
import org.omg.CosNaming.*;
import org.omg.CORBA.*;
import java.io.*;
import java.util.*;
import java.lang.*;

/** testet Quicksort
*
* @author
* @version
*/
public class QuickSortClient  {
  /**
  * 
  */
  public static void main (String [] args) {
   try {
   if (args.length < 3) {
      System.out.println("Usage: java QuickSortClient -ORBInitialHost host Dateiname");
      System.exit(1); }
    String host = args[1];
    File file =  new File( args[4] );
    BufferedReader input = new BufferedReader(new FileReader( file ));
    System.out.println("Einlesen der Folge ");
    String str = input.readLine();
    StringBuffer strB = new StringBuffer();
    while (str != null) {
      strB.append(str); System.out.println(str); strB.append(" ");
      str = input.readLine();
      }
     StringTokenizer st = new StringTokenizer( strB.toString());
    int[] a= new int[st.countTokens()];
    for (int i=0; i<a.length; i++) a[i]= java.lang.Integer.parseInt(st.nextToken());
      // Create and initialize the ORB
      ORB orb = ORB.init(args, null);
      // Get the root naming context
      org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");
      NamingContext ncRef = NamingContextHelper.narrow(objRef);
      // Resolve the object reference in naming
      NameComponent nc = new NameComponent("QuickSort", "");
      NameComponent path[] = {nc};
      Quicks quick= QuicksHelper.narrow(ncRef.resolve(path));
			a = quick.sort(a);
    	System.out.println("sortiert mit QuickSort: ");
    	for (int i=0; i<a.length; i++) System.out.println(a[i]);
			System.out.println();
    	} 
			catch (Exception e) {
      System.err.println("Exception in main: " + e);
    	}
    }
}
